using System;


public class glbUtil
{
    static public bool addInt(ref int v, int d, int maxV)
    {
        if (d < 0)
        {
            throw new System.ArgumentException("value should not < 0");
            return false;
        }

        int newV = v + d;
        if (newV > maxV)
        {
            newV = maxV;
            // log
        }
        else if (newV < v)
        {
            throw new System.ArgumentException("new value should not < old value");
            return false;
        }

        v = newV;
        return true;
    }
    static public bool subInt(ref int v, int d)
    {
        if (d < 0)
        {
            throw new System.ArgumentException("value should not < 0");
            return false;
        }

        if (v < d)
            return false;

        int newV = v - d;
        if (newV > v)
        {
            throw new System.ArgumentException("new value should not > old value");
            return false;
        }

        v = newV;
        return true;
    }
}